package com.wanxi.tcp.demo2客户端一直发送数据给服务器;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * TCP 客户端,演示客户端可以不断的跟服务器端说话，服务器将这些输出到服务器端的控制台
 */
public class TCPClient {
    public static void main(String[] args) throws IOException {
        System.out.println("tcp 客户端启动......");
        //1 创建客户端socket
        Socket clientSocket = new Socket("127.0.0.1", 30000);
        //2 准备发送的信息
        String message = "";
        //3 创建控制台输入流

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//        message = reader.readLine();
        Scanner scanner = new Scanner(System.in);
//        message = scanner.nextLine();
        while ((message = reader.readLine()) != null) {
            //3 发送信息
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
            writer.write(message + "\n");
            writer.flush();
        }
    }
}
